<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
    <title>管理平台</title>
    <jsp:include page="../../include/header.jsp"></jsp:include>
    <style type="text/css">
		table td{
		text-align: center;
		}
	 	table th{
		text-align: center;
	 	}
	</style>
</head>
<body>
<div id="wrapper" class="row">

		<div>
			<div class="col-lg-12">
				<h1 class="page-header">分公司管理</h1>
			</div>
		</div>
		<!-- 搜索框 -->

			<div class="col-lg-12 title-top">
				<label class="search-label">状态：</label>
				<div class="search-input">
					<select id="state" class="selectpicker" data-width="210">
						<option value="0">全部</option>
						<option value="1">上线审核中</option>
						<option value="2">上线</option>
						<option value="3">下线</option>
						<option value="4">驳回</option>
						<option value="5">上线审核中</option><!-- 下线重新上线 -->
						<option value="6">编辑待审核</option>
						<!-- <option value="5">降权</option> -->
											
						<%--  <c:forEach items="${list}" var="store">					
							<option value="${store.state }"><c:if test="${store.state==1}">上线审核中</c:if></option>
							<option value="${store.state }"><c:if test="${store.state==2}">上线</c:if></option>
							<option value="${store.state }"><c:if test="${store.state==3}">下线审核中</c:if></option>
							<option value="${store.state }"><c:if test="${store.state==4}">下线</c:if></option>
						</c:forEach> --%>
						
					</select>
				</div>
				<label class="search-label">分公司ID：</label><input type="text" id="storeid" value="" class="form-control search-input width200" maxlength="21" placeholder="分公司的ID">
				<label class="search-label">分公司名称：</label><input type="text" id="title" value="" class="form-control search-input width200" maxlength="21" placeholder="分公司的名称">
				<button class="btn btn-success search-btn" onclick="query();">确定</button>
				<button class="btn btn-success search-btn" onclick="reset();">重置</button>
				 <div style="float:right;margin-right: 30px;">
						<div class="pull-right">
						<c:if test="${RoleId==2}">
						<button type="button" class="btn btn-success" onclick="toAdd()"><span class="fa fa-plus"></span> 添加分公司</button>
						</c:if>
						<c:if test="${session.userpopedom.dictStoreDoExcel==1}">
						  <button onclick="doExcel();"  class="btn btn-success  width150">导出</button>
						 </c:if>
						</div>
				</div> 
				<div class="clearfix"></div>				
			</div>
				<div class="col-lg-12 ">
					<div class="text-muted single-line-text pull-left">共 <font color="#428bca" id="dataCount">0</font> 条记录</div>
				</div>
	
		<div><p></p></div>

			<div class="col-lg-12">
			
				<div class="table-responsive panel panel-default"><!-- style="width:2520px;  overflow:scroll;"滚动条 -->
					<table id="dataTable"  class="table table-striped table-hover table-bordered" style="overflow:scroll;">
			            <thead>
			                <tr>
								<th width="120px">分公司ID</th>
								<th width="200px">分公司名称</th>
								<th width="100px">主营范围</th>
								<th width="80px">联系人</th>
								<th width="150px">联系电话</th>
								<th width="500px">分公司位置</th>
								<th width="100px">分公司状态</th>
								<th width="200px">创建时间</th>
								<th width="200px">上线时间</th>
								<th width="200px">下线时间</th>		
								<c:if test="${RoleId==2&&power==1}">
								<th width="160px">操作</th>
								 </c:if>
			                </tr>
			            </thead>
			            <tbody id="dataList"></tbody>
			        </table>
				</div>
		        <div class="row">
		        	<div class="col-lg-12">
		        		<ul id="dataPagination" class="pagination-sm pull-right"></ul>
		        	</div>
		        </div>
			</div>
		

</div>
<jsp:include page="../../include/javascripts.jsp"></jsp:include>
<!-- 异步加载下一页数据后，用模板渲染 -->
<script type="text/html" id="dataTpl">
	{{each list as item}}
	<tr id="item{{item.id}}" data-id="{{item.id}}">
		<td>{{item.storeid}}</td>
		<td>{{item.title}}</td>
		<td>{{item.scope | flagTransform:1,'常规',2,'团购',3,'常规+团购'}}</td>			
		<td>{{item.aname}}</td>
		<td>{{item.aphone}}</td>
        <td>{{item.address}}</td>		
        {{if item.qstate==1}}
				{{if item.state==1}}
					<td>上线审核中</td>
				{{else if item.state==2}}
					<td>上线</td>				
				{{else if item.state==3}}
					<td>下线</td>
				{{else if item.state==4}}
					<td>驳回</td>
				{{else if item.state==5}}
					<td>驳回</td>
				{{else if item.state==6}}
					<td>编辑待审核</td>
				{{/if}}
		{{else if item.qstate==2}}           
			 <td>禁货</td>     
		{{else if item.qstate==3}}
			<td>降权</td>
		{{/if}}
			<td>{{item.createtime }}</td>
  {{if item.starttime!=null}}   
  <td>{{item.starttime }}</td> 
  {{else}}
  <td>{{item.starttime }}</td> 
  {{/if}}
{{if item.downtime!=null}}   
  <td>{{item.downtime }}</td> 
  {{else}}
  <td>{{item.downtime }}</td> 
  {{/if}}
     {{if item.qstate==1}}
				{{if item.state==1}}
					<td>
				<a href="javascript:return false;" style="opacity: 0.3"><span class="btn">编辑</span></a>
				<a href="javascript:return false;" style="opacity: 0.3"><span class="btn">下线</span></a>            
					</td>
				{{else if item.state==2}}
					<td>
				<a href="javascript:return false;" style="opacity: 0.3"><span class="btn">编辑</span></a>
				<a href="javascript:Offline('{{item.storeid}}');"><span class="btn">下线</span></a>
					</td>
				{{else if item.state==3}}
					<td>
				<a href="javascript:toEdit('{{item.id}}');"><span class="btn">编辑</span></a>
				<a href="javascript:Online('{{item.storeid}}');"><span class="btn">上线</span></a>
					</td>
                {{else if item.state==4}}
					<td>
				<a href="javascript:toEdit('{{item.id}}');"><span class="btn">编辑</span></a>
				<a href="javascript:BoHui('{{item.storeid}}');"><span class="btn">驳回原因</span></a>
					</td>
				{{else if item.state==6}}
					<td>
				<a href="javascript:return false;" style="opacity: 0.3"><span class="btn">编辑</span></a>
				<a href="javascript:return false;" style="opacity: 0.3"><span class="btn">下线</span></a>    
					</td>
				{{/if}}
             {{else if item.qstate==2}}
		    	<td>
			    <a href="javascript:toEdit('{{item.id}}');"><span class="btn">编辑</span></a>
				<a href="javascript:Online('{{item.storeid}}');"><span class="btn">上线</span></a>
               </td>
		    {{else if item.qstate==3}}
			   <td>
				<a href="javascript:toEdit('{{item.id}}');"><span class="btn">编辑</span></a>
				<a href="javascript:Online('{{item.storeid}}');"><span class="btn">上线</span></a>
			   </td>
		{{/if}}
	</tr>
	{{/each}}
</script>
<script type="text/javascript">
var dataPaginator;
$(query);
function query(){
	var params = {
		pageSize:10,
		state:$("#state").val(),
		storeid:$("#storeid").val(),
		title:$("#title").val()	
	};
	if(dataPaginator){
		dataPaginator.destroy();
	}
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/dict/store/page",params,function(result){
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
	});
	
}
var detailDialog;
function showStore(id){
	detailDialog = Kit.dialog("查看详情","${BASE_PATH}/dict/store/detail?storeid="+id,{closable:true}).open();
}
var addDialog;
function toAdd(){
		addDialog = Kit.dialog("添加","${BASE_PATH}/dict/store/toAdd" ,{closable:false}).open();
}
var bohuilog;
function BoHui(storeid){
	bohuilog = Kit.dialog("驳回原因","${BASE_PATH}/dict/store/toBoHui?storeid="+storeid ,{closable:true}).open();
}
var editDialog;
function toEdit(id){
	editDialog = Kit.dialog("修改","${BASE_PATH}/dict/store/toEdit?id="+id,{closable:true}).open();
}

/* 编辑后定位到原位置 */
 function onEditSuccess(newObject){
		$("#item"+newObject.id).replaceWith(template("dataTpl",{"list":[newObject]}));
 }
function Offline(storeid){
	Kit.confirm("提示","确定要下线吗？",function(ref){
		$.post("${BASE_PATH}/dict/store/Offline",{'storeid':storeid},function(result){
			if(result.flag==0){
				onEditSuccess(result.object);
			}else{
				Kit.alert("操作失败");return;
			}
			
		});
	});
}
function Online(storeid){
	Kit.confirm("提示","确定要发起上线申请吗？",function(ref){
		$.post("${BASE_PATH}/dict/store/Online",{'storeid':storeid},function(result){
			if(result.flag==0){
				onEditSuccess(result.object);
			}else{
				Kit.alert("操作失败");return;
			}
			
		});
	});
}

function doExcel(){
	 var state=$("#state").val(),qstate=$("#state").val(),storeid=$("#storeid").val();
	
		window.location.href="${BASE_PATH}/dict/store/doExcel?state="+state+"&qstate="+qstate+"&storeid="+storeid;
	}
function reset(){
	$("#storeid").val("");
	$("#title").val("");
	 $("#state").val("0");$("#state").trigger("change");
}
</script>
</body>
</html>